﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Go
{
	class RandomBot : AgentBase
	{
		List<Point> candidates = new List<Point>();
		public override Move select_move(GameState game_state)
		{
			// Choose a random valid move that preserves our own eyes
			candidates.Clear();

			for (int r = 1; r <= game_state.board.num_rows; r++)
			{
				for (int c = 1; c <= game_state.board.num_cols; c++)
				{

					var candidate = new Point(r, c);

					if (game_state.is_valid_move(Move.play(candidate)) && 
						!Helpers.is_point_an_eye(game_state.board, candidate, game_state.next_player))
						candidates.Add(candidate);
				}
			}
			if (candidates.Count == 0)
				return Move.pass_turn;

			int rand = UnityEngine.Random.Range(0, candidates.Count);
			return Move.play(candidates[rand]);
		}
	}
}
